/*******************************************************************************
PaddleEntity.cpp

Notes:
*******************************************************************************/

#include "PaddleEntity.h"

// The type associated with a PaddleEntity
const std::string PaddleEntity::Type = "Paddle";

//	PaddleEntity(EntityResource& entityData)
//		Stores the information from the entity resource data
//			entityData - The entity resource data
PaddleEntity::PaddleEntity(EntityResource& entityData)
{
	// Store the width and height
	m_width = (float)atoi(entityData.GetProperty("Width").c_str());
	m_height = (float)atoi(entityData.GetProperty("Height").c_str());

	// Store the speed
	m_fSpeed = (float)atoi(entityData.GetProperty("Speed").c_str());

	// This is not a boundary
	m_isBounds = false;
} // PaddleEntity

//	Update(float fElapsed)
//		Updates the entity state based on the controller's state
void PaddleEntity::Update(float fElapsed)
{
	// This is where we'll get the data from the controller and update the entity
	int moveDirection = m_pController->GetMoveDirection();

	// Move along the Y axis based on the move direction, speed and the time elapsed
	m_y += m_fSpeed * fElapsed * moveDirection;

	// If we have a collision...
	Entity* pEntity = Physics::CheckForCollision(this);
	if(NULL != pEntity && pEntity->IsBounds())
	{
		// If our paddle is too high...
		if(m_y < pEntity->GetY())
		{
			// ... set it to the highest spot
			m_y = pEntity->GetY();
		} // if
		// otherwise, if our paddle is too low...
		else if(m_y + m_height > pEntity->GetY() + pEntity->GetHeight())
		{
			// ... set it to the lowest point
			m_y = (pEntity->GetY() + pEntity->GetHeight()) - m_height;
		} // else if
	} // if
} // Update